package org.soderiakelvy.controller.util;

public class Validar {
    //constructor
    public Validar(){

    }

    public static boolean esDigito(char c){
        boolean res = false;
        if (c>'0'&&c<='9'){
            res = true;
        }
        return res;
    }

    public  static boolean soloLetras(String cad){
        boolean result = false;
        int n = cad.length();		
        int j;
        char c;
        for(j=0; j<n && result==false ; j++){			
            c= cad.charAt(j);			
            if(esDigito(c)){				
                result = true;
            }		
        }
        return result;
    }

    public  static boolean sonNumero(String cadena){
        boolean result = true;
        int n = cadena.length();
        int j;
        char c; 
        for(j=0; j<n && result == true; j++){
            c=cadena.charAt(j);
            if(!(c>='0' && c<='9'))
                result = false;
        }
        return result;
    }
    public static boolean sonLetras(String cadena){
        boolean result = true;
        int n = cadena.length();
        int j;
        char c; 
        for(j=0; j<n && result == true; j++){
            c=cadena.charAt(j);
            if(c>='0' && c<='9')
                result = false;
        }
        return result;
    }
    public static boolean validarTelefono(){
        boolean result = true;
        return result;
    }

    public static boolean validadNombre(String texto){
        boolean result = true;
        if(!(soloLetras(texto))){
            if(texto.length()>30)
                result = false;
        }else result = false;
        return result;
    }
    
    public static boolean isNumeroEntero(String cadena){
        try {
            Integer.parseInt(cadena);
            return true;
        } catch (NumberFormatException nfe){
            return false;
        }
    }
    
    public static boolean isNumeroDouble(String cadena){
        try {
            Double.parseDouble(cadena);
            return true;
        } catch (NumberFormatException nfe){
            return false;
        }
    }
    
    public static boolean isNumeroFloat(String cadena){
    	try {
			Float.parseFloat(cadena);
			return true;
		} catch (Exception e) {
			return false;
		}
    }
}
